package com.innovation.sys.common.utils;

import org.apache.shiro.crypto.RandomNumberGenerator;
import org.apache.shiro.crypto.SecureRandomNumberGenerator;
import org.apache.shiro.crypto.hash.SimpleHash;
import org.apache.shiro.util.ByteSource;

public class PasswordUtils {

	private static RandomNumberGenerator randomNumberGenerator = new SecureRandomNumberGenerator();
	private static String algorithmName = "md5";
	private final static int hashIterations = 2;

	public static String encryptPassword(String salt,String password){
		String newPassword = new SimpleHash(algorithmName, password,
				ByteSource.Util.bytes(salt), hashIterations).toHex();
		return newPassword;
	}
	
	public static String generateSalt() {
		return randomNumberGenerator.nextBytes().toHex();
	}
	
	public static void main(String [] args){
		System.out.println(generateSalt());
		System.out.println(encryptPassword("w","password"));
	}
}
